<template>
    <view>
        <view class="getCash">
            <view class="cash_box_1">
                <view class="small_class_text">充值金额</view>
                <view class="small_img_box"><button class="charge_button"  @tap="getChargeList()">充值记录</button></view>
            </view>
            <view class="cash_box_2">
                <view class="money_img">￥</view>
                <view><input class="money_num" type="number" v-model="cashMoney" placeholder="0" /></view>
            </view>
            <view>
                <view class="vis_money">充值方式</view>
                <view class="img_box"><image class="wx_pay" :src="img_url+'static/img/wxpay.png'"/></view>
<!--                <view class="vis_money">可提现金额 ￥{{has_money}}</view>-->
<!--                <view class="all_money" @tap="allGetCash()">全部提现</view>-->
            </view>

        </view>
        <view class="cash_button_box" @tap="queryCash()"><button class="cash_button">立即充值</button></view>
    </view>

</template>

<script>
    export default {
        name: "getCharge",
        data() {
            return {
                cashMoney:'',
                has_money:'',
                img_url:this.$mConfig.assetsPath
            }
        },
        mounted() {
            this.getUserInfo()
        },
        methods: {
            allGetCash(){
                this.cashMoney=this.has_money
            },
            async queryCash(){ //确认提现
                let reg=/^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/
                if(this.cashMoney===''){
                    uni.showToast({
                        title:"请输入正确的提现金额",
                        icon: 'none'
                    })
                    return
                }
                if(!reg.test(this.cashMoney)){
                    uni.showToast({
                        title:"请输入正确的提现金额",
                        icon: 'none'
                    })
                    return
                }
                let resData = await  this.$apis.getCash({price:this.cashMoney})
                if(resData.code===0){
                    uni.showToast({
                        title:"提交成功",
                        icon: 'success'
                    })
                    let user_data = await this.$apis.getUserInfo({access_token:''})
                    await this.$store.commit("SET_USERINFO",user_data.data)
                    setTimeout(()=>{
                        uni.reLaunch({
                            url: '/pages/main/user'
                        })
                    },1000)
                }

            },
            getChargeList(){
                this.$router.push({
                    route:this.$routesConfig.getChargeList,
                })
            },
            async getUserInfo(){
                let resData = await  this.$apis.getUserInfo({access_token:''})
                if(resData.code===0){
                    this.has_money=resData.data.price
                }
            },

        },
    }
</script>
<style>
    page {
        background-color:#FAFAFA
    }
</style>
<style lang="less" scoped>
    .getCash{
        background-color: #ffffff;
        margin-top: 2rpx;
    }
    .cash_box_1{
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        margin-left: 20rpx;
        margin-top: 10rpx;
        padding-top: 30rpx;
    }
    .small_img{
        width: 30rpx;
        height: 30rpx;
        transform: translate(0,2%);
    }
    .small_class_text{
        font-size: 29rpx;
        font-family: SourceHanSansCN-Normal;
        color: #333333;
    }
    .cash_box_2{
        display: flex;
        flex-direction: row;
        font-size: 50rpx;
        margin-left: 20rpx;
        margin-top: 30rpx;
    }
    .money_img{
        /*border-right: solid 0.5px #cccccc;*/
    }
    .money_num{
        padding-top: 10rpx;
    }
    .cash_box_3{
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        margin-left: 20rpx;
        margin-top: 30rpx;
        padding-bottom: 30rpx;
    }
    .vis_money{
        font-size: 30rpx;
        color: #0D0D0D;
        margin-bottom: 20rpx;
        margin-top: 20rpx;
        margin-left: 20rpx;
        padding-top: 20rpx;
        border-top: solid 0.5px #cccccc ;
    }
    .all_money{
        font-size: 29rpx;
        color: #FF9400;
        margin-right: 20rpx;
    }
    .cash_button{
        color: #ffffff;
        background-color: #FF9502;
        border-radius: 50rpx;
        width: 80%;
        margin-top: 300rpx;
    }
    .small_img_box{
        margin-left: 10rpx;
    }
    .wx_pay{
        height: 80rpx;
        width: 80rpx;
    }
    .img_box{
        margin-left: 20rpx;
    }
    .charge_button{
        height: 65rpx;
        width: 180rpx;
        background-color: #FF9502;
        color: #ffffff;
        font-size: 28rpx;
        margin-right: 20rpx;

    }

</style>
